package com.syq.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.syq.service.ElkServiceImpl;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @ClassName: SearchController
 * @Description: TODO
 * @Create by: syq
 * @Date: 2022/8/30 10:29
 */

@RestController
public class SearchController {

    @Autowired
    private ObjectMapper objectMapper;

    @Autowired
    private RestHighLevelClient restHighLevelClient;

    @Autowired
    private ElkServiceImpl elkService;

    /**
     * 根据条件查询日志集合数据返回
     * @param paras
     */
    @RequestMapping(value = "/search/search", method = RequestMethod.POST)
    public List<Map> searchLog(@RequestParam("params") String paras) throws Exception {
        Map map = objectMapper.readValue(paras, Map.class);

        return elkService.searchlog(map);
    }

    /**
     * 根据条件查询日志总条数
     * @param paras
     */
    @RequestMapping(value = "/search/searchcount", method = RequestMethod.POST)
    public Long searchLogCount(@RequestParam("params") String paras) throws Exception {
        Map map = objectMapper.readValue(paras, Map.class);
        Long aLong = elkService.searchAll(map);
        System.out.println(aLong);
        return aLong;
    }

    /**
     * 统计报表查询
     * @param paras
     */
    @RequestMapping(value = "/search/statStatus", method = RequestMethod.POST)
    public Map<String, Long> statSendStatus(@RequestParam("params") String paras) throws Exception {
        Map map = objectMapper.readValue(paras, Map.class);

        return elkService.searchStatus(map);

    }
}
